package com.naiterui.ehp.bs.b2c.product.controller.inner;

import javax.validation.constraints.NotNull;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.naiterui.common.repository.page.PageVO;
import com.naiterui.ehp.bp.bo.doctor.product.ProductInfoBO;
import com.naiterui.ehp.bp.bo.doctor.product.ProductSearchParamBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.support.utils.JsonMapper;
import com.naiterui.ehp.bs.b2c.product.service.ICommonDrugService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

/**
 * 医生常用药
 * 
 * @author yangfuya
 * @since 2022/3/29
 */
@Slf4j
@Api(tags = SwaggerTag.DOCTOR + SwaggerTag.COMMON_DRUG)
@RestController
@RequiredArgsConstructor
@RequestMapping("b2c/inner/common/drug")
public class InnerCommonDrugController {
    private final ICommonDrugService commonDrugService;

    /**
     * 医生常用药我的列表
     * 
     * @param productSearch
     * @return
     */
    @ApiOperation(value = "医生常用药我的列表")
    @PostMapping("/list")
    public PageVO<ProductInfoBO> list(@RequestBody ProductSearchParamBO productSearch) {
        log.info("医生常用药我的列表: {}", JsonMapper.toJson(productSearch));
        return commonDrugService.list(productSearch);
    }

    /**
     * 医生常用药使用列表
     *
     * @param productSearch
     * @return
     */
    @ApiOperation(value = "医生常用药使用列表")
    @PostMapping("/use/list")
    public PageVO<ProductInfoBO> useList(@RequestBody ProductSearchParamBO productSearch) {
        log.info("医生常用药我使用列表: {}", JsonMapper.toJson(productSearch));
        return commonDrugService.useList(productSearch);
    }

    /**
     * 添加常用药
     *
     * @param doctorId
     *            医生id
     * @param productId
     *            药品id
     */
    @ApiOperation(value = "添加常用药")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "doctorId", value = "医生ID", paramType = "path", dataType = "long", required = true),
        @ApiImplicitParam(name = "productId", value = "药品ID", paramType = "path", dataType = "long", required = true)})
    @PostMapping("/add/{doctorId}/{productId}")
    public void addCommonDrug(@PathVariable("doctorId") @NotNull(message = "doctorId不能为null") Long doctorId,
        @PathVariable("productId") @NotNull(message = "productId不能为null") Long productId) throws BusinessException {
        log.info("添加常用药请求参数, doctorId = {}, productId = {}", doctorId, productId);
        this.commonDrugService.addCommonDrug(doctorId, productId);
    }

    /**
     * 移除常用药
     *
     * @param doctorId
     *            医生id
     * @param productId
     *            药品id
     */
    @ApiOperation(value = "移除常用药")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "doctorId", value = "医生ID", paramType = "path", dataType = "long", required = true),
        @ApiImplicitParam(name = "productId", value = "药品ID", paramType = "path", dataType = "long", required = true)})
    @PostMapping("/remove/{doctorId}/{productId}")
    public void removeCommonDrug(@PathVariable("doctorId") @NotNull(message = "doctorId不能为null") Long doctorId,
        @PathVariable("productId") @NotNull(message = "productId不能为null") Long productId) throws BusinessException {
        log.info("移除常用药请求参数, doctorId = {}, productId = {}", doctorId, productId);
        this.commonDrugService.removeCommonDrug(doctorId, productId);
    }
}
